package com.dankegongyu.lib.common.paging;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import androidx.annotation.NonNull;

/**
 * @author wupuquan
 * @version 1.0
 * @since 2020/4/17 10:40
 */
public class PagingData<T> {

    private int totalCount;
    private List<T> pagingData;
    private int pageCount;
    private boolean isFirstPage;
    private boolean hasNextPage;

    PagingData(int totalCount, List<T> pagingData, boolean isFirstPage, boolean hasNextPage) {
        this.totalCount = totalCount;
        this.pagingData = pagingData != null ? pagingData : new ArrayList<T>();
        this.pageCount = this.pagingData.size();
        this.isFirstPage = isFirstPage;
        this.hasNextPage = hasNextPage;
    }

    /**
     * 数据总条数
     */
    public int getTotalCount() {
        return totalCount;
    }

    /**
     * 分页数据条数
     */
    public int getPageCount() {
        return pageCount;
    }

    /**
     * 分页数据
     */
    @NonNull
    public List<T> getPagingData() {
        return Collections.unmodifiableList(pagingData != null ? pagingData : new ArrayList<T>());
    }

    public boolean isFirstPage() {
        return isFirstPage;
    }

    public boolean hasNextPage() {
        return hasNextPage;
    }

    @SuppressWarnings("NullableProblems")
    @Override
    public String toString() {
        return "PagingData{" +
                "totalCount=" + totalCount +
                ", pageCount=" + pageCount +
                ", pagingData=" + pagingData +
                ", isFirstPage=" + isFirstPage +
                ", hasNextPage=" + hasNextPage +
                '}';
    }
}
